const http = require('http');

http.createServer((req, res) => {
  const agent = req.headers['user-agent'];
  console.log(agent);

  if(agent.match('iPhone')){
    res.statusCode = 302;
    res.setHeader('Location', 'http://www.baidu.com');
    res.end();
  }else{
    res.statusCode = 302;
    res.setHeader('Location', 'http://www.qq.com');
    res.end();
  }
}).listen(5000);

// User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36

// User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
